python if not none in one line

28

#if X is None, do nothing
>>> x = ''
>>> x if x and x>0 else None
#if x is not None, print it
>>> x = 1
>>> x if x and x>0 else None
1
v = get_value()
x = v if v is not None

Comments

Submit
0 Comments